package loginRegister;

/**
 *
 * @author 黄忠
 */
import Bean.SqlBean;

public class LoginBean extends SqlBean {
    private String userName;
    private String name;
    private String level;
    private String password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public LoginBean(){
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    public boolean login(){
        boolean result=false;
        try{
            connectSQL();
            String sql="select * from user where userName='"+userName+"' AND password='"+password+"'";
            rs=stmt.executeQuery(sql);
            if(rs.next()){
                name=rs.getString("name");
                level=rs.getString("level");
                result=true;
            }
            closeSQL();
        }catch(Exception e){
            e.printStackTrace();
        }
        return result;
    }
    public boolean register(){
        boolean result=false;
        try{
            connectSQL();
            String sql="select * from user where userName='"+userName+"'";
            rs=stmt.executeQuery(sql);
            if(!rs.next()) {
                sql="insert into user"+"(userName,password)"+"values("+"'"+userName+"'"+","+"'"+password+"'"+")";
                stmt.executeUpdate(sql);
                result=true;
            }
            closeSQL();
        }catch(Exception e){
            e.printStackTrace();
        }
        return result;
    }
}
